﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package Display.hud.components {
    import flash.events.*;
    import Engine.Managers.*;
    import flash.display.*;
    import flash.utils.*;
    import Display.*;
    import Modules.quest.Display.*;
    import flash.media.*;
    import com.adobe.utils.*;

    public class HUDQuestBarComponent extends HUDComponent {

        public static const NAME:String = "QuestSidebar";

        protected var m_icons:Dictionary;
        private var m_removedBanners:Dictionary;
        private var m_questIconClickVolume:SoundTransform;
        protected var m_container:Container;
        private var m_bannerQueue:Array;
        protected var m_questNames:Array;

        public function HUDQuestBarComponent(_arg1:Number=10, _arg2:Number=10, _arg3:Number=0, _arg4:Number=260, _arg5:uint=4, _arg6:int=1, _arg7:int=400, _arg8:int=350):void{
            var locX:int = _arg1;
            var locY:int = _arg2;
            var width:int = _arg3;
            var height:int = _arg4;
            var numSlots:int = _arg5;
            var direction:int = _arg6;
            var mask_width:int = _arg7;
            var mask_height:int = _arg8;
            super();
            this.m_container = new Container(numSlots, direction, locX, locY, width, height, mask_width, mask_height);
            this.m_container.name = NAME;
            this.addChild(this.m_container);
            var sfxVolume:* = 0.5;
            try {
                sfxVolume = Global.gameSettings.getXML().sounds.sound.(@name == "click1").@volume;
            } catch(err:Error) {
            };
            this.m_questIconClickVolume = new SoundTransform(sfxVolume);
            this.m_icons = new Dictionary();
            this.m_questNames = new Array();
            this.m_removedBanners = new Dictionary();
            this.m_bannerQueue = new Array();
        }
        override public function cleanUp():void{
            var _local1:String;
            var _local2:Array;
            var _local3:QuestOverlaySprite;
            var _local4:String;
            this.m_bannerQueue.splice(0, this.m_bannerQueue.length);
            for (_local1 in this.m_icons) {
                _local4 = this.m_icons[_local1].name;
                this.removeIcon(_local4, this.m_icons[_local1].clickCallback, false);
                delete this.m_icons[_local4];
            };
            _local2 = DictionaryUtil.getKeys(this.m_removedBanners);
            for each (_local3 in _local2) {
                this.m_removedBanners[_local3].cleanUp();
                delete this.m_removedBanners[_local3];
            };
        }
        public function cleanUpBanner(_arg1:QuestOverlaySprite):void{
            if (this.m_removedBanners.hasOwnProperty(_arg1)){
                delete this.m_removedBanners[_arg1];
            };
        }
        override public function refresh(_arg1:Boolean):void{
            if (Global.questManager){
                Global.questManager.refreshActiveIconQuests();
            };
        }
        public function get container():Container{
            return (this.m_container);
        }
        protected function createSidebarSprite(_arg1, _arg2:String="Placeholder for tooltip"):GameSprite{
            var _local3:GameSprite = new GameSideBarSprite();
            _arg1.addEventListener(MouseEvent.MOUSE_MOVE, this.containerMouseMove);
            _local3.addChild(_arg1);
            _local3.toolTip = _arg2;
            return (_local3);
        }
        public function addIcon(_arg1:String, _arg2:String, _arg3:DisplayObject, _arg4:Function, _arg5:int=0):Boolean{
            if (((_arg1) && (this.m_icons.hasOwnProperty(_arg1)))){
                return (false);
            };
            var _local6:GameSprite = this.createSidebarSprite(_arg3, _arg2);
            _local6.name = _arg1;
            _local6.buttonMode = true;
            _local6.useHandCursor = true;
            _local6.addEventListener(MouseEvent.CLICK, _arg4);
            _local6.hideCursor = true;
            this.m_icons[_arg1] = new IconData(_arg1, _arg4);
            this.m_questNames.push(_arg1);
            StatsManager.count("quest_icons", "q_hud_add", _arg1);
            return (this.m_container.push(_local6, _arg5));
        }
        public function removeIcon(_arg1:String, _arg2:Function, _arg3:Boolean=true):DisplayObject{
            var _local8:DisplayObjectContainer;
            var _local4:Number = this.m_container.numChildren;
            var _local5:DisplayObject;
            var _local6:DisplayObject;
            var _local7:int;
            while (_local7 < _local4) {
                if (this.container.getChildAt(_local7)){
                    _local8 = (this.container.getChildAt(_local7) as DisplayObjectContainer);
                    _local5 = _local8.getChildByName(_arg1);
                    if (_local5 != null){
                        _local6 = _local5;
                        this.container.slotClick(null, (_local8 as ContainerSlot), false);
                        _local5.removeEventListener(MouseEvent.CLICK, _arg2);
                    };
                };
                _local7++;
            };
            this.removeAllQueued(_arg1);
            if (_arg3){
                this.removeBanner(_arg1);
            } else {
                this.removeBanner(_arg1, true);
            };
            delete this.m_icons[_arg1];
            if (this.m_questNames.indexOf(_arg1) >= 0){
                this.m_questNames.splice(this.m_questNames.indexOf(_arg1), 1);
            };
            return (_local6);
        }
        protected function removeAllQueued(_arg1:String):void{
            var _local2:int = (this.m_bannerQueue.length - 1);
            while (_local2 >= 0) {
                if (this.m_bannerQueue[_local2].name == _arg1){
                    this.m_bannerQueue.splice(_local2, 1);
                };
                _local2--;
            };
        }
        public function showBanner(_arg1:String, _arg2:String, _arg3:Boolean=false):void{
            this.m_bannerQueue.push({
                name:_arg1,
                type:_arg2,
                persist:_arg3
            });
            this.pumpBannerQueue();
        }
        public function removeBanner(_arg1:String, _arg2:Boolean=false):void{
            if (((this.m_icons.hasOwnProperty(_arg1)) && (this.m_icons[_arg1].banner))){
                this.m_removedBanners[this.m_icons[_arg1].banner] = this.m_icons[_arg1].banner;
                if (_arg2){
                    this.m_icons[_arg1].banner.cleanUp();
                    this.cleanUpBanner(this.m_icons[_arg1].banner);
                } else {
                    this.m_icons[_arg1].banner.remove();
                };
                this.m_icons[_arg1].banner = null;
            };
            this.pumpBannerQueue();
        }
        protected function pumpBannerQueue():void{
            var _local1:IconData;
            var _local2:Object;
            var _local3:String;
            var _local4:String;
            var _local5:Boolean;
            var _local6:Number;
            var _local7:int;
            var _local8:DisplayObjectContainer;
            var _local9:*;
            var _local10:QuestOverlaySprite;
            for each (_local1 in this.m_icons) {
                if (_local1.banner){
                    return;
                };
            };
            if (this.m_bannerQueue.length > 0){
                _local2 = this.m_bannerQueue[0];
                _local3 = _local2.name;
                _local4 = _local2.type;
                _local5 = _local2.persist;
                _local6 = this.m_container.numChildren;
                _local7 = 0;
                while (_local7 < _local6) {
                    if (this.container.getChildAt(_local7)){
                        _local8 = (this.container.getChildAt(_local7) as DisplayObjectContainer);
                        _local9 = _local8.getChildByName(_local3);
                        if (_local9 != null){
                            if (this.m_icons.hasOwnProperty(_local3)){
                                _local10 = new QuestOverlaySprite(_local4, _local5, _local3);
                                _local10.mouseChildren = false;
                                _local10.mouseEnabled = false;
                                _local9.addChild(_local10);
                                this.m_icons[_local3].banner = _local10;
                            };
                        };
                    };
                    _local7++;
                };
                this.m_bannerQueue.shift();
            };
        }
        public function containerMouseMove(_arg1:MouseEvent):void{
            var _local2:* = _arg1.target.parent;
            _local2.buttonMode = true;
            _local2.useHandCursor = true;
        }
        public function get clickVolume():SoundTransform{
            return (this.m_questIconClickVolume);
        }
        public function get questNames():Array{
            return (this.m_questNames);
        }

    }
}//package Display.hud.components 

import Modules.quest.Display.*;

class IconData {

    public var name:String;
    public var banner:QuestOverlaySprite;
    public var clickCallback:Function;

    public function IconData(_arg1:String, _arg2:Function=null){
        this.name = _arg1;
        this.clickCallback = _arg2;
        this.banner = null;
    }
}
